package com.helloworld.demo.threadbase;

public class ThreadStop {
    public static void main(String[] args) {
        Object lock = new Object();
        long s = System.currentTimeMillis();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock){
                    System.out.println(Thread.currentThread().getName() + "获取锁...");
                    try {
                        System.out.println(Thread.currentThread().getName() + "excute0...");
                        Thread.sleep(60000);
                        System.out.println(Thread.currentThread().getName() + "excute1...");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(Thread.currentThread().getName() + "end...");
            }
        });
        thread.start();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        thread.stop();
        long e = System.currentTimeMillis();
        System.out.println(e - s);

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "wait lock...");
                synchronized (lock){
                    System.out.println(Thread.currentThread().getName() + "excute...");
                }
            }
        });
        thread1.start();
    }
}
